package com.eascs.crm.web.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.eascs.crm.common.vo.QueryCustomerVO;
import com.eascs.crm.web.service.SelectDataServiceImpl;
import com.eascs.site.controller.BaseRestController;
import com.eascs.site.view.BaseRestResult;
import com.eascs.web.sso.UserHolder;
import com.eascs.workflow.common.entity.sys.ActOrgEntity;
import com.eascs.workflow.common.service.sys.SysOrgService;
import com.eascs.workflow.common.vo.ModelResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.inject.Inject;
import java.util.List;

@Controller
@RequestMapping("/common")
public class CommonController extends BaseRestController {
	
	@Inject
	SelectDataServiceImpl selectDataService;
	
	@Reference
	SysOrgService sysOrgService;
	
	@RequestMapping(value = "/searchUnit")
	public BaseRestResult<List<Object[]>> searchUnit(QueryCustomerVO vo) {
		 ModelResult<List<Object[]>> model = sysOrgService.getOrgListLikeName(vo.getOrg_name(), ActOrgEntity.ORG_LEVEL_PLATFORM,UserHolder.getUser());
		return BaseRestResult.buildRestResult(model.getModel());
	}
	
	/**
	 * @Title: findProvinces
	 * @Description: 查询所有的省区字典数据
	 * @author longlong.wang
	 * @return
	 * @return List<Object[]>
	 * @throws @date
	 * 2017年1月11日 上午11:07
	 */
	@RequestMapping(value = "/findProvinces")
	public BaseRestResult<List<Object[]>> findProvince() {
		List<Object[]> data = selectDataService.getDataSouce("province", null);
		return BaseRestResult.buildRestResult(data);

	}

	/**
	 * @Title: findCityByProvinceCode
	 * @Description: 通过省区code，查询市区信息
	 * @author 张庆奇
	 * @param provinceCode
	 * @return
	 * @return List<Object[]>
	 * @throws @date
	 *             2016年6月1日 下午2:33:12
	 */
	@RequestMapping(value = "/findCityByProvinceCode")
	public BaseRestResult<List<Object[]>> findCityByProvinceCode(String provinceCode) {
		List<Object[]> data = selectDataService.getDataSouce("city", provinceCode);
		return BaseRestResult.buildRestResult(data);

	}

	/**
	 * @Title: findDistrictByCityCode
	 * @Description: 通过市区code查询区县
	 * @author 张庆奇
	 * @param cityCode
	 * @return
	 * @return List<Object[]>
	 * @throws @date
	 *             2016年6月1日 下午2:32:35
	 */
	@RequestMapping(value = "/findDistrictByCityCode")
	public BaseRestResult<List<Object[]>> findDistrictByCityCode(String cityCode) {
		List<Object[]> data = selectDataService.getDataSouce("country", cityCode);
		return BaseRestResult.buildRestResult(data);
	}

}
